package strcy.cn.market.mapper;

import org.apache.ibatis.annotations.*;
import strcy.cn.market.pojo.User;

import java.util.List;

@Mapper
public interface UserMapper {

    //添加用户
    @Insert("insert into users(username, password, email, created_at, idcard, age, province, city, district, addr, avatar,role,state) " +
            "values(#{username},#{password},#{email},now(),#{idcard},#{age},#{province},#{city},#{district},#{addr},#{avatar},#{role},#{state})")
    void add(User user);

    //通过邮箱查询
    @Select("select * FROM users where email=#{email}")
    User getByEmail(String email);

    //获取全部用户信息
    @Select("select * FROM users")
    List<User> getUserAll();

    //根据Id查询用户
    @Select("select * FROM users where user_id = #{id}")
    User getUserById(Integer id);
    //更新用户信息
    @Update("update users set username=#{username},state=#{state},province=#{province},avatar=#{avatar},idcard=#{idcard},age=#{age}," +
            "city=#{city},district=#{district},addr=#{addr} where user_id = #{userId}")
    void update(User user);

    //根据ID删除用户
    @Delete("delete from users where user_id=#{id}")
    void deleteById(Integer id);
    //更新用户头像URL
    @Update("update users set avatar=#{avatarUrl} where user_id =#{id}")
    void updateAvatar(String avatarUrl, Integer id);

    //更新密码
    @Update("update users set password =#{password} where user_id =#{id}")
    void updatePwd(String password, Integer id);
    //根据Id更新用户状态
    @Update("update users set state=#{status} where user_id=#{id}")
    void updateStatusById(Integer id,String status);
}
